﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yugi.Client.Card;
using ServerYuGi;
using ServerYuGi.CardScriptDatabase;
using ServerYuGi.PythonRegister;
using ManagementEffect;

namespace APIEffect.CARD
{
    public partial class CARD_API
    {
        public void Card_CanExcute(bool result,byte ID)
        {
            if (result)                       
            {
                if (CheckIsAsk(ID))
                    return;

                if (super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenBan(ID)
                    || super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenTay(ID))
                {
                    if(!super.ExEffectManager.ListID_TrongLuot.Contains(ID))
                        super.ExEffectManager.ListID_TrongLuot.Add(ID);
                }              
            }
            
        }
        public void Card_CanRegister(bool result, byte ID)
        {
            super.pyregister.DangKyScript(result, ID);

        }

        public void Card_CanExcute2(bool result, byte ID)
        {
            if (result)
            {
                

                if (super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenBan(ID)
                    || super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenTay(ID))
                {
                    if (!super.ExEffectManager.ListID_TrongLuot.Contains(ID))
                        super.ExEffectManager.ListID_TrongLuot.Add(ID);
                }
            }
            else
            {
                if (super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenBan(ID) 
                    || super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenTay(ID))
                {
                    SCard card = super.LayPlayer(super.ExEffectManager.IDPlayerCheck).LayCardInAll(ID);
                    CardScript script = super.CScriptDB.GetScript(card.MyYBaseCard.Card_TypeID);
                    super.pyregister.AddStore(script.GetListCheckPoint(), ID);
                }
            }

        }
        public void Card_CanExcute3(bool result, byte ID)
        {
            if (result)
            {
                if (super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenBan(ID)
                    || super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenTay(ID))
                {
                    if (!super.ExEffectManager.ListID_TrongLuot.Contains(ID))
                        super.ExEffectManager.ListID_TrongLuot.Add(ID);
                }
            }
            if (super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenBan(ID)
                || super.LayPlayer(super.ExEffectManager.IDPlayerCheck).CheckIDCardTrenTay(ID))
            {
                SCard card = super.LayPlayer(super.ExEffectManager.IDPlayerCheck).LayCardInAll(ID);
                CardScript script = super.CScriptDB.GetScript(card.MyYBaseCard.Card_TypeID);
                super.pyregister.AddStore(script.GetListCheckPoint(), ID);
            }

        }

        bool CheckIsAsk(byte ID)
        {
            if(super.EffectTurnManager.Is_Check_No_Ask)
            {
                SCard CardAddChain = super.LayPlayer(super.ExEffectManager.IDPlayerCheck).LayCardInAll(ID);
                if (CardAddChain == null)
                    return true;
                int SpeedCardActive = CardAddChain.MyYBaseCard.Speed;
                super.ChainMnager.AddChain(new List<YCheckPoint> {super.ExEffectManager.CheckPointNow }, ID, CardAddChain.MyYBaseCard.Card_TypeID, SpeedCardActive);
                //-------------------------------------------------------------------------//

                // Xoa Store la active neu co
                super.pyregister.RemoveIDinStore(CardAddChain);
                return true;
            }
            return false;
        }

        public void Card_Stop_Process()
        {
            super.ExEffectManager.isResumeProgress = false;
        }

        
    }
}
